package com.sgcc.epri.dcloud.conf.http;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassDescription: 初始化restTemplate的配置类
 * 通过@Configuration和@Bean将创建的RestTemplate注入容器中
 * @Author：李白
 * @Date：2023/4/3 15:54
 */
@Configuration
public class RestTemplateConfig {

    @Value("${nr.connectTime}")
    private int connectTime;

    @Value("${nr.readTime}")
    private int readTime;

    @Bean
    public RestTemplate restTemplate(){
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

        // 设置连接超时时间（毫秒）
        requestFactory.setConnectTimeout(connectTime);
        // 设置读取超时时间（毫秒）
        requestFactory.setReadTimeout(readTime);

        return new RestTemplate(requestFactory);
    }
}

